|
|
|
|
|
|
|
The Class_Initialize event, then, would have the following code structure: |
|
|
|
|
|
|
|
|
Private Sub Class_Initialize()
#If DebugMode Then
'get the next available class ID, and print out
'that the class was created successfully
mlClassDebugID = GetNextClassDebugID()
Debug.Print ' & TypeName(Me) & ' instance & _ mlClassDebugID
& created
#End If
'Your code here
End Sub |
|
|
|
|
|
|
|
|
The debugging function, GetNextClassDebugID(), assigns the next available class debug ID number to the current class instance. The GetNextClassDebugID() function resides in the global ModClassIDGenerator module. The function is as follows: |
|
|
|
|
|
|
|
|
Function GetNextClassDebugID() As Long
'class ID generator
Static lClassDebugID As Long
lClassDebugID = lClassDebugID + 1
GetNextClassDebugID = lClassDebugID
End Function |
|
|
|
|
|
|
|
|
The Class_Terminate event has a similar structure: |
|
|
|
|
|
|
|
|
Private Sub Class_Terminate()
'the class is being destroyed
#If DebugMode Then
Debug.Print ' & TypeName(Me) & ' instance & _
CStr(mlClassDebugID) & is terminating
#End If
End Sub |
|
|
|
|
|
|
|
|
The Debug.Print line prints the object's type (class) name and debug identifier to the debug console window at runtime. To have To have Class Builder insert debugging code in your classes, choose Add-Ins|Class Builder Utility from the menu. In Class Builder, choose View|Options. You should see the Class Builder Options dialog box, as illustrated in Figure 8.1. Click the check box for Include Debug Code in Initialize and Terminate Events. |
|
|
|
|
|
|
|
|
Figure 8.1.
Use the Class Builder Options dialog box to
insert debug code into your applications. |
|
|
|
|
|